#!/usr/bin/perl
# removes all lines with a timestamp date below the given first arg
use strict;
use warnings;

# find the name of the sms_table
my $sms_table = "";
my $line;
if (open (my $conf, "<", "dbconf.sh")) {
        # look for the sms_table line
        while (<$conf>) {
                if (m/^\s*sms_table\s*=\s*"(.*)"/) {
                        $sms_table=$1 if $1;
                        last;
                }
                $sms_table="Inbox" if (! "$sms_table");
        }
        close($conf);
} else {
        $sms_table="Inbox";
}

my ($x);  # placeholders

my $latest = $ARGV[0];
shift;

while (<>) {
$x = $_;
# reformat the date string to be mysqlish
	if ($x =~ m/^Insert into $sms_table values \('','Inbox','([[:digit:]]{4})-([[:digit:]]{2})-([[:digit:]]{2}) ([[:digit:]]{2}):([[:digit:]]{2}):([[:digit:]]{2})'/) {
		if (("$1$2$3$4$5$6" cmp "$latest") > 0) {
			print "$x";
		}
	} else {
		print "$x";
	}
}


